<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="/css/common.css" />
		<link rel="stylesheet" type="text/css" href="/bootstrap-3.3.7/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="/css/flatpickr.min.css" />
		<link rel="stylesheet" type="text/css" href="/css/font-awesome.css"/>
		<link rel="stylesheet" type="text/css" href="/dialog/css/dialog.css"/>

		<script src="/js/jquery-1.9.1.min.js" type="text/javascript"></script>
		<script src="/js/google-maps.js" type="text/javascript" charset="utf-8"></script>
		<script src="/js/jquery.validate.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/dialog/js/dialog.js" type="text/javascript" charset="utf-8"></script>
		<script src="/js/jquery.form.js"></script>
		<script src="/js/common.js"></script>
		<script src="/js/flatpickr.js" type="text/javascript" charset="utf-8"></script>
		<script src="/js/messages_zh.min.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<!--顶部导航 -->
		<nav class="topNavItemBox">
			<div id="ItemBox">
				<div class="title">肉品溯源管理系统</div>
			</div>
		</nav>
		<!-- 左侧导航 -->
		<#include "left.ftl"/>

        <!-- 新增生猪入场信息 -->
		<div class="page_main">
			<h3>新增生猪入厂信息</h3><span class="add_link"><a href="/admin/PigIn/findByCondition">查询生猪入厂信息></a></span>
			<br />
			<div class="page_content">
				
				<form id="quarantine_addform" action="/admin/PigIn/addPigIn" method="post">
					<ul>
						<li><label class="labelBeforinput">生猪编号</label><input name="purGid" class="bigInputtext" maxlength="9" required data-rule-isIntGtZero="true" type="text" /></li>
						<li><label class="labelBeforinput">入场重量</label><input name="inweight"  class="bigInputtext" required type="text" ></li>
						<li><label class="labelBeforinput">重量单位</label><input name="weightunit" class="bigInputtext" required type="text" value="kg"/></li>
						<li><label class="labelBeforinput">生猪等级</label><input name="grade" class="bigInputtext" data-rule-isIntGtZero="true" required type="text" /></li>
						<li><label class="labelBeforinput">入厂日期</label><input name="intime" class="bigInputtext" id="inTime" required data-date-format="Y-m-d" /></li>
						<#--<li><label class="labelBeforinput">厂区ID</label><input name="areAreaid" class="bigInputtext" required  data-rule-isIntGtZero="true" type="text" /></li>-->
						<li><label class="labelBeforinput">厂区ID</label><select name="areAreaid"  class="bigInputtext" required  data-rule-NotZero="true" ><option value="0">请选择</option></select></li>
						<li><label class="labelBeforinput">接收企业</label><select name="comGid"  id="comGid" onchange="change()" class="bigInputtext" required  data-rule-NotZero="true" ><option value="0">请选择</option></select></li>
						<li><label class="labelBeforinput">接收人姓名</label><input name="receivername" class="bigInputtext"  type="text" /></li>
						<li><label class="labelBeforinput">供货企业</label><select name="comGid2" class="bigInputtext" required data-rule-NotZero="true" /><option value="0">请选择</option></select></li>
						<li><label class="labelBeforinput">供货人姓名</label><input name="supplyname" class="bigInputtext" required type="text" /></li>
						<li><label class="labelBeforinput">供货人电话</label><input name="supplytel" class="bigInputtext" required type="text" /></li>
						<li><label class="labelBeforinput">采购地点</label><input name="buyplace" class="bigInputtext" required type="text" /></li>
						<li><label class="labelBeforinput">采购序号</label><input name="buysn" class="bigInputtext" required type="text" /></li>
						<li><label class="labelBeforinput">备注</label><input name="remark" class="bigInputtext"  type="text" /></li>
				
						<li><input type="submit" value="添加记录" style="margin-left: 170px; width: 200px;" /></li>
					</ul>
				</form>
			</div>
			<div class="footer">
				<div class="footer_lineone">
					<span id="logo"></span>肉品溯源管理系统 
					<span class="footer_lineoneSpan"><a href="aboutus.html">关于我们</a></span>
					<span class="footer_lineoneSpan"><a target="_blank" href="http://www.cfsiw.com/">食品安全信息</a></span> 
					<span class="footer_lineoneSpan"><a href="suggestionAdd.ftl">联系我们</a></span>
				</div>
				<div class="footer_linetwo">
					 &copy;2017广东技术师范学院
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		$(function() {
			//初始化侧边栏
			$(".vertical-nav").verticalnav({
				speed: 400,
				align: "left"
			});
			
			//时间控制器
			$("#inTime").flatpickr();
			//表单校验
			$("#quarantine_addform").validate();
			//异步下拉
			$.post("/admin/company/findCompanyByFeedType?typeID=1001", function(data) {
				for(var i = 0; i < data.length; i++) {
					$("select[name='comGid']").append("<option value='" + data[i].gid + "'>" + data[i].compname + "</option>");
					}
			});	
			$.post("/admin/company/findCompanyByFeedType?typeID=1001", function(data) {
                for(var i = 0; i < data.length; i++) {
					$("select[name='comGid2']").append("<option value='" + data[i].gid + "'>" + data[i].compname + "</option>");
					}
			});




			//表单提交
			$("#quarantine_addform").ajaxForm({

					success:function(data) {
						var str = null;
						var msg = null;
						if(data.msg == 1){
							str = "success";
							msg = "生猪入场成功";
                            $.dialog({
                                type: 'info',
                                contentHtml: '<img class="info-icon" src="dialog/images/icon/'+str+'.png" alt="'+msg+'" />',
                                autoClose: 2000
                            });
                            setTimeout('window.location="/admin/PigIn/findByCondition"',3000);

						}else{
							str = "fail";
							msg = data.msg.message;
						}
						console.log(data);
						$.dialog({
							type: 'info',
							contentHtml: '<img class="info-icon" src="dialog/images/icon/'+str+'.png" alt="'+msg+'" /><p class="info-text">'+msg+'</p>',
							autoClose: 2000
						});
					}
			});
		});

        //异步查询公司厂区ID
        function  change() {
            var ID = $("#comGid").val();
            if(ID != 0){
                $.get("/admin/area/findArea?ID="+ID+"", function(data) {
                    for(var i = 0; i < data.length; i++) {
                        $("select[name='areAreaid']").append("<option value='" + data[i].areaid + "'>" + data[i].areaid + "养殖区</option>");
                    }
                });
            }
        }
	</script>

</html>